package advanced.datastructure;

import structure5.*;
import java.util.Comparator;

public class MyVector<E> extends Vector<E> {

	public MyVector()
	{
		super();
	}
	
	// pre: c is a valid comparator
	// post: sort this vector in order determined by c
	public void sort(Comparator<E> c)
	{
		int numSorted = 1; // number of values in place
		int index; // general index
		int n = size(); // length of the array
		while (numSorted < n)
		{
			// take the first unsorted value
			E temp = get(numSorted);
			// ...and insert it among the sorted:
			for (index = numSorted; index > 0; index--)
			{
				if (c.compare(temp,get(index-1)) < 0)
				{
					set(index, get(index-1));
				} 
				else 
				{
					break;
				}
			}
			// reinsert value
			set(index, temp);
			numSorted++;
		}
	}
}